import 'package:flutter/material.dart';

class Counter0104 extends StatefulWidget {
  const Counter0104({Key ? key}) : super(key: key);

  // 必须实现一个createState方法或者是build方法
  @override
  _CounterState createState() => _CounterState();
}

class _CounterState extends State<Counter0104> {
  int _counter = 0;

  void _increment () {
    setState(() {
      _counter++;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Row(mainAxisAlignment: MainAxisAlignment.center,
      children: <Widget>[
        ElevatedButton(onPressed: _increment, child: const Text('Increment')),
        const SizedBox(width: 16),
        Text('Count: $_counter'),
      ],
    );
  }
}